package org.dxy.infrastructure.persistent.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.dxy.infrastructure.persistent.po.query.BomItemViewPo;
import org.dxy.infrastructure.persistent.mapper.BomItemViewMapper;
import org.dxy.infrastructure.persistent.service.BomItemViewService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * BOM物料项查询服务实现
 */
@Service
public class BomItemViewServiceImpl extends ServiceImpl<BomItemViewMapper, BomItemViewPo> implements BomItemViewService {
    
    @Override
    public List<BomItemViewPo> listByBomId(Long bomId) {
        LambdaQueryWrapper<BomItemViewPo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BomItemViewPo::getBomId, bomId)
                   .orderByAsc(BomItemViewPo::getSortOrder);
        return list(queryWrapper);
    }
    
    @Override
    public List<BomItemViewPo> listByBomIds(List<Long> bomIds) {
        if (bomIds == null || bomIds.isEmpty()) {
            return List.of();
        }
        LambdaQueryWrapper<BomItemViewPo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(BomItemViewPo::getBomId, bomIds)
                   .orderByAsc(BomItemViewPo::getBomId, BomItemViewPo::getSortOrder);
        return list(queryWrapper);
    }
    
    @Override
    public boolean deleteByBomId(Long bomId) {
        LambdaQueryWrapper<BomItemViewPo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BomItemViewPo::getBomId, bomId);
        return remove(queryWrapper);
    }
}